//
//  ITem3CollectionViewCell.m
//  WangI
//
//  Created by dllo on 15/11/25.
//  Copyright © 2015年 WJN. All rights reserved.
//

#import "ITem3CollectionViewCell.h"

@implementation ITem3CollectionViewCell
//@synthesize  array = _array;
-(void)dealloc {
    [_tableView release];
    [super dealloc];
}
-(instancetype) initWithFrame:(CGRect)frame  {
    self = [super initWithFrame:frame];
    if (self) {
        [self getData];
        [self addSubview:self.tableView];
        [self.tableView release];
        
    }
    return self;
}
-(void)getData {
    [SANetWorkingTask request:kNewsGETURL2 parmater:nil block:^(id result) {
        NSArray *array = result[@"T1348649079062"];
        //NSLog(@"%@",array);
        for (NSDictionary *dic in array) {
            NewsModel *newsModel = [[NewsModel alloc] initWithDataSource:dic];
            [self.dataSource addObject:newsModel];
            
        }
        NSLog(@"%@",self.dataSource);
        [self.tableView reloadData];
    }];
}
-(NSMutableArray *)dataSource {
    if (!_dataSource) {
        self.dataSource = [[NSMutableArray alloc] initWithCapacity:0];
        
    }
    return _dataSource;
}
-(UITableView *)tableView {
    if (!_tableView) {
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) style:UITableViewStyleGrouped];
        [_tableView release];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self.tableView registerClass:[NewsTableViewCell class] forCellReuseIdentifier:@"hehe"];
        [self.tableView registerClass:[GuLuTableViewCell class] forCellReuseIdentifier:@"wuwu"];
    }
    return _tableView;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.dataSource[indexPath.row]imgextraSource]) {
        GuLuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"wuwu"];
        NewsModel *newModel = self.dataSource[indexPath.row];
        [cell setNewsModel:newModel];
        return cell;
    } else {
        NewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"hehe"];
        NewsModel *newModel = self.dataSource[indexPath.row];
        [cell setNewsModel:newModel];
        return cell;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 300;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    NewsModel *newsModel = [[NewsModel alloc] init];
    imgsrcModel *imgsrcView = [[imgsrcModel alloc] init];
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
    
    newsModel = [self.dataSource firstObject];
    NSLog(@"%ld", newsModel.adsArray.count);
    
    for (int i = 0; i < newsModel.adsArray.count; i++) {
        imgsrcView = newsModel.adsArray[i];
        NSString *string = imgsrcView.imgsrc;
        [array addObject:string];
        NSString *string1 = newsModel.imgsrc;
        [array addObject:string1];

    }
    
    ScrollWithImage *scroll = [[ScrollWithImage alloc] initWithFrame:self.
                               bounds];
    [self addSubview:scroll];
    [scroll release];
    [scroll setArray:array];
    [scroll setNewsModel:newsModel];
    return scroll;
}

@end
